package com.gr.controller;


import com.gr.entity.*;
import com.gr.service.ISkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.Set;

/**
 * <p>
 * sku信息 前端控制器
 * </p>
 *
 * @author guoran
 * @since 2022-05-11
 */
@RestController
@RequestMapping("/skuInfo")
public class SkuInfoController {
    @Autowired
    private ISkuInfoService skuInfoService;
    //toDo
    @PostMapping("/add")
    public ResultEntity add(@RequestBody SkuDto dto){
        skuInfoService.save(dto.getSku());
        Map<String, String> attrValues = dto.getAttrValues();
        Set<Map.Entry<String, String>> entries = attrValues.entrySet();
        for (Map.Entry entry:entries){
            String key = (String) entry.getKey();
            long attrId = Long.parseLong(key);
            String attrValue = (String) entry.getValue();
            SkuSaleAttrValue skuSaleAttrValue = new SkuSaleAttrValue(attrId,attrValue);
        }
        return ResultEntity.ok();
    }
}

